#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;

class CQueue {
public:
    CQueue() {
    }
    
    void appendTail(int value) {
        if(this->S2.empty()){
            this->S1.push(value);
            this->S2.push(S1.top());
            this->S1.pop();
        }
        else{
            while(!S2.empty()){
                S1.push(S2.top());
                S2.pop();
            }
            S1.push(value);
            while(!S1.empty()){
                S2.push(S1.top());
                S1.pop();
            }
        }
    }
    
    int deleteHead() {
        if(S2.empty()){
            return -1;
        }
        else{
            int T = S2.top();
            S2.pop();
            return T;
        }
    }
public:
    stack<int> S1;
    stack<int> S2;
};

int main(){
    CQueue Q;
    cout<<Q.deleteHead()<<endl;
    Q.appendTail(5);
    Q.appendTail(2);
    cout<<Q.deleteHead()<<endl;
    cout<<Q.deleteHead()<<endl;

}